import Vue from 'vue'
import axios from 'axios'

import App from './App'
import router from './router'
import store from './store'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import pool from './utils/datastore'

import cmd from 'node-cmd'

Vue.use(ElementUI)

Vue.http = Vue.prototype.$http = axios
Vue.config.productionTip = false

Vue.prototype.$pool = pool

Vue.prototype.$cmd = cmd

/* eslint-disable no-new */
window.app = new Vue({
  components: { App },
  router,
  store,
  template: '<App/>'
}).$mount('#app')

// 登录拦截
router.beforeEach((to, from, next) => {
  let flag = sessionStorage.getItem('user_id')
  // if (to.meta.requiresAuth === true) { // 需要登录权限进入的路由
  //   if (!flag) {
  //     next({
  //       path: '/login'
  //     })
  //   } else {
  //     return next()// 获取到登录信息进行下一步
  //   }
  // } else { // 不需要权限登录的直接进行下一步
  //   return next()
  // }
  if (!flag) {
    next({
      path: '/login'
    })
  } else {
    return next()// 获取到登录信息进行下一步
  }
})
